package cn.tedu.hospitalgroupproject.server.content.dao.persist.repository.impl;

import cn.tedu.hospitalgroupproject.server.common.pojo.vo.PageData;
import cn.tedu.hospitalgroupproject.server.common.util.PageInfoToPageDataConverter;
import cn.tedu.hospitalgroupproject.server.content.dao.persist.mapper.ClinicMapper;
import cn.tedu.hospitalgroupproject.server.content.dao.persist.repository.IClinicRepository;
import cn.tedu.hospitalgroupproject.server.content.pojo.entity.Clinic;
import cn.tedu.hospitalgroupproject.server.content.pojo.entity.Doctor;
import cn.tedu.hospitalgroupproject.server.content.pojo.param.ClinicUpdateInfoParam;
import cn.tedu.hospitalgroupproject.server.content.pojo.vo.ClinicListVO;
import cn.tedu.hospitalgroupproject.server.content.pojo.vo.ClinicStandardVO;
import cn.tedu.hospitalgroupproject.server.content.pojo.vo.DepartmentListVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Slf4j
@Repository
public class ClinicRepositoryImpl implements IClinicRepository {

    @Autowired
    private ClinicMapper clinicMapper;

    public ClinicRepositoryImpl() {
        log.info("创建存储库对象:ClinicRepositoryImpl");
    }

    @Override
    public int insert(Clinic clinic) {
        log.debug("开始向[门诊表]中插入数据:{}",clinic);
        return clinicMapper.insert(clinic);
    }

    @Override
    public int deleteById(Long id) {
        log.debug("开始执行[删除指定门诊ID数据]:{}",id);
        return clinicMapper.deleteById(id);
    }

    @Override
    public int updateById(Clinic clinic) {
        log.debug("开始执行[更新指定门诊ID数据],新的诊所数据:{}",clinic);
        return clinicMapper.updateById(clinic);
    }

    @Override
    public ClinicStandardVO getStandardById(Long id) {
        log.debug("开始执行[根据ID查找门诊数据],id:{}",id);
        return clinicMapper.getStandardById(id);
    }

    @Override
    public int countByDeptId(Long id) {
        log.debug("开始执行[计算指定科室ID下门诊个数]:{}",id);

        return clinicMapper.selectClinicByDeptId(id).size();
    }

    @Override
    public PageData<ClinicListVO> list(Integer pageNum, Integer pageSize) {
        log.debug("开始执行【查询门诊列表】，页码：{}，每页记录数：{}", pageNum, pageSize);
        PageHelper.startPage(pageNum, pageSize);
        List<ClinicListVO> list = clinicMapper.listClinic();
        PageInfo<ClinicListVO> pageInfo = new PageInfo<>(list);
        PageData<ClinicListVO> pageData = PageInfoToPageDataConverter.convert(pageInfo);
        return pageData;
    }
}
